// Data Base
// (c) jimon game studio

#ifndef JEH_CDATABASE
#define JEH_CDATABASE

#include "IDataBase.h"
#include "sqlite3.h"
#include "SQLite/CppSQLite3.h"

namespace je
{
	namespace core
	{
		//! Data Base Query
		class CDataBase_Query:public je::core::IDataBase_Query
		{
		protected:
			CppSQLite3Query Query;
		public:
			//! Constructor
			CDataBase_Query(CppSQLite3Query query);

			//! Destructor
			~CDataBase_Query();

			//! Finalize
			void Finalize();

			//! Eof
			u1 Eof();

			//! Next Row
			void NextRow();

			//! Return Int Field
			s32 GetFields32(const jeStringc & FieldName,s32 DefaultValue = 0);

			//! Return Int Field
			s32 GetFields32(s32 Index,s32 DefaultValue = 0);

			//! Return Float Field
			f32 GetFieldf32(const jeStringc & FieldName,f32 DefaultValue = 0);

			//! Return Float Field
			f32 GetFieldf32(s32 Index,f32 DefaultValue = 0);

			//! Return Boolean Field
			u1 GetFieldu1(const jeStringc & FieldName,u1 DefaultValue = false);

			//! Return Boolean Field
			u1 GetFieldu1(s32 Index,u1 DefaultValue = false);

			//! Return jeStringc Field
			jeStringc GetFieldjeStringc(const jeStringc & FieldName,const jeStringc & DefaultValue = "");

			//! Return jeStringc Field
			jeStringc GetFieldjeStringc(s32 Index,const jeStringc & DefaultValue = "");

			//! Return Field Binary Data
			jeMemoryBuffer * GetFieldBuffer(const jeStringc & FieldName);

			//! Return Field Binary Data
			jeMemoryBuffer * GetFieldBuffer(s32 Index);

			//! Is Field Exist
			u1 IsFieldExist(const jeStringc & FieldName);
		};

		//! Data Base
		class CDataBase:public je::core::IDataBase
		{
		protected:
			CppSQLite3DB * DataBase;
		public:
			//! Constructor
			CDataBase(const jeStringc & FileName);

			//! Destructor
			~CDataBase();

			//! Query
			IDataBase_Query * Query(const jeStringc & Query);

			//! Return Field Binary Data With Streaming
			IBlobBuffer * GetBlobBuffer(const jeStringc & Table,const jeStringc & FieldName,const s32 RowId);

		};
	}
}

#endif
